﻿<Page x:Class="OldSchoolMdiDemo._3DThing"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d"
      d:DesignHeight="300" d:DesignWidth="300"
	Title="3DThing">

    <Border>
        <Border.Background>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                <GradientStop Color="AliceBlue" Offset="0" />
                <GradientStop Color="Blue" Offset="1" />
            </LinearGradientBrush>
        </Border.Background>

        <Border.Resources>
            <Storyboard x:Key="RotateModel">
                <Rotation3DAnimationUsingKeyFrames BeginTime="00:00:00" RepeatBehavior="Forever"
			 Storyboard.TargetName="GasketModel"
			 Storyboard.TargetProperty="(Model3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation)">
                    <SplineRotation3DKeyFrame KeyTime="00:00:02">
                        <SplineRotation3DKeyFrame.Value>
                            <AxisAngleRotation3D Angle="180" Axis="0,1,0"/>
                        </SplineRotation3DKeyFrame.Value>
                    </SplineRotation3DKeyFrame>
                    <SplineRotation3DKeyFrame KeyTime="00:00:04">
                        <SplineRotation3DKeyFrame.Value>
                            <AxisAngleRotation3D Angle="359" Axis="0,1,0"/>
                        </SplineRotation3DKeyFrame.Value>
                    </SplineRotation3DKeyFrame>
                </Rotation3DAnimationUsingKeyFrames>
            </Storyboard>
        </Border.Resources>

        <Border.Triggers>
            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard Storyboard="{StaticResource RotateModel}"/>
            </EventTrigger>
        </Border.Triggers>

        <Viewport3D Margin="4,4,4,4">
            <Viewport3D.Camera>
                <PerspectiveCamera
				Position="2, 2, 4"
				LookDirection="-2, -2, -4"
				UpDirection="0, 1, 0"
				FieldOfView="60"/>
            </Viewport3D.Camera>

            <Viewport3D.Resources>
                <!-- The material used by most surfaces. -->
                <DiffuseMaterial x:Key="matGreen" Brush="LightGreen"/>
            </Viewport3D.Resources>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup x:Name="GasketModel">
                        <Model3DGroup.Transform>
                            <Transform3DGroup>
                                <RotateTransform3D />
                            </Transform3DGroup>
                        </Model3DGroup.Transform>

                        <!-- Lights -->
                        <AmbientLight Color="#FF404040"/>
                        <DirectionalLight Color="Gray" Direction="-1,-2,0" />
                        <DirectionalLight Color="Gray" Direction="0,0,-1" />
                        <DirectionalLight Color="Gray" Direction="0,0,2" />
                        <DirectionalLight Color="#FF202020" Direction="1,0,0" />

                        <!-- 3D objects go here. -->
                        <!-- Top -->
                        <GeometryModel3D Material="{StaticResource matGreen}">
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
							 Positions="-1,1,1 1,1,1 1,1,-1 -1,1,-1"
							 TriangleIndices="0,1,3 1,2,3"/>
                            </GeometryModel3D.Geometry>
                        </GeometryModel3D>
                        <!-- Right -->
                        <GeometryModel3D Material="{StaticResource matGreen}">
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
							 Positions="1,1,1 1,-1,1 1,-1,-1 1,1,-1"
							 TriangleIndices="0,1,3 1,2,3"/>
                            </GeometryModel3D.Geometry>
                        </GeometryModel3D>
                        <!-- Back -->
                        <GeometryModel3D Material="{StaticResource matGreen}">
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
							 Positions="1,1,-1 1,-1,-1 -1,-1,-1 -1,1,-1"
							 TriangleIndices="0,1,3 1,2,3"/>
                            </GeometryModel3D.Geometry>
                        </GeometryModel3D>
                        <!-- Left -->
                        <GeometryModel3D Material="{StaticResource matGreen}">
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
							 Positions="-1,1,-1 -1,-1,-1 -1,-1,1 -1,1,1"
							 TriangleIndices="0,1,3 1,2,3"/>
                            </GeometryModel3D.Geometry>
                        </GeometryModel3D>
                        <!-- Bottom -->
                        <GeometryModel3D Material="{StaticResource matGreen}">
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
							 Positions="-1,-1,1 -1,-1,-1 1,-1,-1 1,-1,1"
							 TriangleIndices="0,1,3 1,2,3"/>
                            </GeometryModel3D.Geometry>
                        </GeometryModel3D>

                        <!-- Front -->
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D>
                                    <MeshGeometry3D.Positions>
                                        <Point3D X="-1" Y="1" Z="1"/>
                                        <Point3D X="-1" Y="-1" Z="1"/>
                                        <Point3D X="1" Y="-1" Z="1"/>
                                        <Point3D X="1" Y="1" Z="1"/>
                                    </MeshGeometry3D.Positions>
                                    <MeshGeometry3D.TextureCoordinates>
                                        <Point X="0" Y="0"/>
                                        <Point X="0" Y="1"/>
                                        <Point X="1" Y="1"/>
                                        <Point X="1" Y="0"/>
                                    </MeshGeometry3D.TextureCoordinates>
                                    <MeshGeometry3D.TriangleIndices>
                                        <Int32Collection>
                                            0,1,2 2,3,0
                                        </Int32Collection>
                                    </MeshGeometry3D.TriangleIndices>
                                </MeshGeometry3D>
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <MaterialGroup>
                                    <DiffuseMaterial>
                                        <DiffuseMaterial.Brush>
                                            <ImageBrush ImageSource="Jellyfish.jpg"/>
                                        </DiffuseMaterial.Brush>
                                    </DiffuseMaterial>
                                </MaterialGroup>
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>
    </Border>
</Page>
